home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / comm / term / term_source.lha / Extras / Source / term-source.lha / Scroll.c < prev    next >
C/C++ Source or Header  |  1996-10-20  |  28KB  |  1,500 lines

  1. /*
  2. **    Scroll.c
  3. **
  4. **    Support routines for optimized screen scrolling.
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16.     /* ScrollFrameUpdate(VOID):
  17.      *
  18.      *    Optimize the area to be scrolled by moving the top and
  19.      *    bottom lines as needed.
  20.      */
  21.  
  22. STATIC VOID
  23. ScrollFrameUpdate(VOID)
  24. {
  25.     while(ScrollLineFirst < RasterHeight && !ScrollLines[ScrollLineFirst].Width)
  26.         ScrollLineFirst++;
  27.  
  28.     while(ScrollLineLast > 0 && !ScrollLines[ScrollLineLast].Width)
  29.         ScrollLineLast--;
  30. }
  31.  
  32.     /* ScrollLineRectFill():
  33.      *
  34.      *    Fill a rectangular portion of the window raster with the help
  35.      *    of the scrolling information.
  36.      */
  37.  
  38. VOID
  39. ScrollLineRectFill(struct RastPort *RPort,LONG MinX,LONG MinY,LONG MaxX,LONG MaxY)
  40. {
  41.     if(MinX < MaxX && MinY < MaxY)
  42.     {
  43.         LONG Start,Stop;
  44.         LONG BackPen;
  45.  
  46.         if(FgPen == BgPen || (Attributes & ATTR_INVERSE))
  47.             BackPen    = FgPen;
  48.         else
  49.             BackPen = BgPen;
  50.  
  51.         Start    = MinY / TextFontHeight;
  52.         Stop    = MaxY / TextFontHeight;
  53.  
  54.         if(BackPen)
  55.         {
  56.             if(UseMasking)
  57.             {
  58.                 LONG Mask = BackPen,i;
  59.  
  60.                 for(i = Start ; i <= Stop ; i++)
  61.                 {
  62.                     if(ScrollLines[i].Width)
  63.                         Mask |= ScrollLines[i].ColourMask;
  64.  
  65.                     ScrollLines[i].Left            = 0;
  66.                     ScrollLines[i].Right        = LastColumn + 1;
  67.                     ScrollLines[i].Width        = TextFontWidth;
  68.                     ScrollLines[i].ColourMask    = BackPen;
  69.                 }
  70.  
  71.                 SetMask(RPort,Mask);
  72.             }
  73.             else
  74.             {
  75.                 LONG i;
  76.  
  77.                 for(i = Start ; i <= Stop ; i++)
  78.                 {
  79.                     ScrollLines[i].Left            = 0;
  80.                     ScrollLines[i].Right        = LastColumn + 1;
  81.                     ScrollLines[i].Width        = TextFontWidth;
  82.                     ScrollLines[i].ColourMask    = BackPen;
  83.                 }
  84.             }
  85.  
  86.             if(Start < ScrollLineFirst)
  87.                 ScrollLineFirst = Start;
  88.  
  89.             if(Stop > ScrollLineLast)
  90.                 ScrollLineLast = Stop;
  91.  
  92.             ScrollFrameUpdate();
  93.         }
  94.         else
  95.         {
  96.             LONG ScrollLineLeft,ScrollLineRight,ScrollLineWidth;
  97.  
  98.             ScrollLineLeft    = 32767;
  99.             ScrollLineRight    = 0;
  100.             ScrollLineWidth    = 0;
  101.  
  102.             if(UseMasking)
  103.             {
  104.                 LONG Mask = 0,i;
  105.  
  106.                 for(i = Start ; i <= Stop ; i++)
  107.                 {
  108.                     if(ScrollLines[i].Width)
  109.                     {
  110.                         if(ScrollLines[i].Width > ScrollLineWidth)
  111.                             ScrollLineWidth = ScrollLines[i].Width;
  112.  
  113.                         if(ScrollLines[i].Left < ScrollLineLeft)
  114.                             ScrollLineLeft = ScrollLines[i].Left;
  115.  
  116.                         if(ScrollLines[i].Right > ScrollLineRight)
  117.                             ScrollLineRight = ScrollLines[i].Right;
  118.  
  119.                         Mask |= ScrollLines[i].ColourMask;
  120.                     }
  121.  
  122.                     ScrollLines[i].Left            = 32767;
  123.                     ScrollLines[i].Right        = 0;
  124.                     ScrollLines[i].Width        = 0;
  125.                     ScrollLines[i].ColourMask    = 0;
  126.                 }
  127.  
  128.                 if(Mask)
  129.                     SetMask(RPort,Mask);
  130.                 else
  131.                 {
  132.                     ScrollFrameUpdate();
  133.  
  134.                     return;
  135.                 }
  136.             }
  137.             else
  138.             {
  139.                 LONG i;
  140.  
  141.                 for(i = Start ; i <= Stop ; i++)
  142.                 {
  143.                     if(ScrollLines[i].Width)
  144.                     {
  145.                         if(ScrollLines[i].Width > ScrollLineWidth)
  146.                             ScrollLineWidth = ScrollLines[i].Width;
  147.  
  148.                         if(ScrollLines[i].Left < ScrollLineLeft)
  149.                             ScrollLineLeft = ScrollLines[i].Left;
  150.  
  151.                         if(ScrollLines[i].Right > ScrollLineRight)
  152.                             ScrollLineRight = ScrollLines[i].Right;
  153.                     }
  154.  
  155.                     ScrollLines[i].Left            = 32767;
  156.                     ScrollLines[i].Right        = 0;
  157.                     ScrollLines[i].Width        = 0;
  158.                     ScrollLines[i].ColourMask    = 0;
  159.                 }
  160.             }
  161.  
  162.             if(ScrollLineWidth)
  163.             {
  164.                 LONG Temp;
  165.  
  166.                 if((Temp = ScrollLineLeft * ScrollLineWidth) > MinX)
  167.                     MinX = Temp;
  168.  
  169.                 if((Temp = ScrollLineRight * ScrollLineWidth) < MaxX)
  170.                     MaxX = Temp;
  171.  
  172.                 if(MaxX == ScrollLineRight)
  173.                     MaxX += FontRightExtend;    /* Add margin for italics or boldface. */
  174.  
  175.                 if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  176.                     MinY = Temp;
  177.  
  178.                 if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  179.                     MaxY = Temp;
  180.             }
  181.  
  182.             if(Start < ScrollLineFirst)
  183.                 ScrollLineFirst = Start;
  184.  
  185.             if(Stop > ScrollLineLast)
  186.                 ScrollLineLast = Stop;
  187.  
  188.             ScrollFrameUpdate();
  189.  
  190.             if(!ScrollLineWidth)
  191.                 return;
  192.         }
  193.  
  194.             /* And clear the raster. */
  195.  
  196.         if(MinX < MaxX && MinY < MaxY)
  197.         {
  198.             MinX += WindowLeft;
  199.             MinY += WindowTop;
  200.             MaxX += WindowLeft;
  201.             MaxY += WindowTop;
  202.  
  203.             if(FgPen == BgPen || (Attributes & ATTR_INVERSE))
  204.                 RectFill(RPort,MinX,MinY,MaxX,MaxY);
  205.             else
  206.             {
  207.                 SetAPen(RPort,BgPen);
  208.                 RectFill(RPort,MinX,MinY,MaxX,MaxY);
  209.                 SetAPen(RPort,FgPen);
  210.             }
  211.         }
  212.     }
  213. }
  214.  
  215. VOID
  216. ScrollLineRectFillNoTabChange(struct RastPort *RPort,LONG MinX,LONG MinY,LONG MaxX,LONG MaxY)
  217. {
  218.     if(MinX < MaxX && MinY < MaxY)
  219.     {
  220.         LONG Start,Stop;
  221.         LONG BackPen;
  222.  
  223.         if(FgPen == BgPen || (Attributes & ATTR_INVERSE))
  224.             BackPen    = FgPen;
  225.         else
  226.             BackPen = BgPen;
  227.  
  228.         Start    = MinY / TextFontHeight;
  229.         Stop    = MaxY / TextFontHeight;
  230.  
  231.         if(BackPen)
  232.         {
  233.             if(UseMasking)
  234.             {
  235.                 LONG Mask,i;
  236.  
  237.                 Mask = BackPen;
  238.  
  239.                 for(i = Start ; i <= Stop ; i++)
  240.                 {
  241.                     if(ScrollLines[i].Width)
  242.                         Mask |= ScrollLines[i].ColourMask;
  243.                 }
  244.  
  245.                 SetMask(RPort,Mask);
  246.             }
  247.  
  248.             if(Start < ScrollLineFirst)
  249.                 ScrollLineFirst = Start;
  250.  
  251.             if(Stop > ScrollLineLast)
  252.                 ScrollLineLast = Stop;
  253.  
  254.             ScrollFrameUpdate();
  255.         }
  256.         else
  257.         {
  258.             LONG ScrollLineLeft,ScrollLineRight,ScrollLineWidth;
  259.  
  260.             ScrollLineLeft    = 32767;
  261.             ScrollLineRight    = 0;
  262.             ScrollLineWidth    = 0;
  263.  
  264.             if(UseMasking)
  265.             {
  266.                 LONG Mask,i;
  267.  
  268.                 Mask = 0;
  269.  
  270.                 for(i = Start ; i <= Stop ; i++)
  271.                 {
  272.                     if(ScrollLines[i].Width)
  273.                     {
  274.                         if(ScrollLines[i].Width > ScrollLineWidth)
  275.                             ScrollLineWidth = ScrollLines[i].Width;
  276.  
  277.                         if(ScrollLines[i].Left < ScrollLineLeft)
  278.                             ScrollLineLeft = ScrollLines[i].Left;
  279.  
  280.                         if(ScrollLines[i].Right > ScrollLineRight)
  281.                             ScrollLineRight = ScrollLines[i].Right;
  282.  
  283.                         Mask |= ScrollLines[i].ColourMask;
  284.                     }
  285.                 }
  286.  
  287.                 if(Mask)
  288.                     SetMask(RPort,Mask);
  289.                 else
  290.                 {
  291.                     ScrollFrameUpdate();
  292.  
  293.                     return;
  294.                 }
  295.             }
  296.             else
  297.             {
  298.                 LONG i;
  299.  
  300.                 for(i = Start ; i <= Stop ; i++)
  301.                 {
  302.                     if(ScrollLines[i].Width)
  303.                     {
  304.                         if(ScrollLines[i].Width > ScrollLineWidth)
  305.                             ScrollLineWidth = ScrollLines[i].Width;
  306.  
  307.                         if(ScrollLines[i].Left < ScrollLineLeft)
  308.                             ScrollLineLeft = ScrollLines[i].Left;
  309.  
  310.                         if(ScrollLines[i].Right > ScrollLineRight)
  311.                             ScrollLineRight = ScrollLines[i].Right;
  312.                     }
  313.                 }
  314.             }
  315.  
  316.             if(ScrollLineWidth)
  317.             {
  318.                 LONG Temp;
  319.  
  320.                 if((Temp = ScrollLineLeft * ScrollLineWidth) > MinX)
  321.                     MinX = Temp;
  322.  
  323.                 if((Temp = ScrollLineRight * ScrollLineWidth) < MaxX)
  324.                     MaxX = Temp;
  325.  
  326.                 if(MaxX == ScrollLineRight)
  327.                     MaxX += FontRightExtend;    /* Add margin for italics or boldface. */
  328.  
  329.                 if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  330.                     MinY = Temp;
  331.  
  332.                 if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  333.                     MaxY = Temp;
  334.             }
  335.  
  336.             if(Start < ScrollLineFirst)
  337.                 ScrollLineFirst = Start;
  338.  
  339.             if(Stop > ScrollLineLast)
  340.                 ScrollLineLast = Stop;
  341.  
  342.             ScrollFrameUpdate();
  343.  
  344.             if(!ScrollLineWidth)
  345.                 return;
  346.         }
  347.  
  348.             /* And clear the raster. */
  349.  
  350.         if(MinX < MaxX && MinY < MaxY)
  351.         {
  352.             MinX += WindowLeft;
  353.             MinY += WindowTop;
  354.             MaxX += WindowLeft;
  355.             MaxY += WindowTop;
  356.  
  357.             if(FgPen == BgPen || (Attributes & ATTR_INVERSE))
  358.                 RectFill(RPort,MinX,MinY,MaxX,MaxY);
  359.             else
  360.             {
  361.                 SetAPen(RPort,BgPen);
  362.                 RectFill(RPort,MinX,MinY,MaxX,MaxY);
  363.                 SetAPen(RPort,FgPen);
  364.             }
  365.         }
  366.     }
  367. }
  368.  
  369.     /* ScrollLineRaster():
  370.      *
  371.      *    Scroll the window raster with the help
  372.      *    of the scrolling information.
  373.      */
  374.  
  375. VOID
  376. ScrollLineRaster(struct RastPort *RPort,LONG DeltaX,LONG DeltaY,LONG MinX,LONG MinY,LONG MaxX,LONG MaxY,BOOL Smooth)
  377. {
  378.     if((DeltaX || DeltaY) && MinX < MaxX && MinY < MaxY)
  379.     {
  380.         LONG Start,Stop;
  381.         LONG BackPen;
  382.         BOOL ResetPen;
  383.  
  384.         if((Attributes & ATTR_INVERSE) && (FgPen != BgPen))
  385.         {
  386.             SetBPen(RPort,FgPen);
  387.  
  388.             ResetPen    = TRUE;
  389.             BackPen        = FgPen;
  390.         }
  391.         else
  392.         {
  393.             ResetPen    = FALSE;
  394.             BackPen        = BgPen;
  395.         }
  396.  
  397.         Start    = MinY / TextFontHeight;
  398.         Stop    = MaxY / TextFontHeight;
  399.  
  400.         if(BackPen)
  401.         {
  402.             if(UseMasking)
  403.             {
  404.                 LONG i,Mask;
  405.  
  406.                 Mask = BackPen;
  407.  
  408.                 for(i = Start ; i <= Stop ; i++)
  409.                 {
  410.                     if(ScrollLines[i].Width)
  411.                         Mask |= ScrollLines[i].ColourMask;
  412.                 }
  413.  
  414.                 SetMask(RPort,Mask);
  415.             }
  416.  
  417.             if(DeltaX)
  418.             {
  419.                 if(!ScrollLines[CursorY].Width)
  420.                 {
  421.                     if(ResetPen)
  422.                         SetBPen(RPort,BgPen);
  423.  
  424.                     return;
  425.                 }
  426.                 else
  427.                 {
  428.                     ScrollLines[CursorY].Left    = 0;
  429.                     ScrollLines[CursorY].Right    = (LastPixel + 1) / ScrollLines[CursorY].Width;
  430.  
  431.                     ScrollLines[CursorY].ColourMask |= BackPen;
  432.                 }
  433.             }
  434.             else
  435.             {
  436.                 LONG i,Lines,Size;
  437.  
  438.                 Lines    = DeltaY / TextFontHeight;
  439.                 Size    = (MaxY - MinY + 1) / TextFontHeight;
  440.  
  441.                 if(Lines < 0)
  442.                 {
  443.                     Lines = -Lines;
  444.  
  445.                     if(Size <= Lines)
  446.                     {
  447.                         for(i = 0 ; i < Size ; i++)
  448.                         {
  449.                             ScrollLines[Start + i].Left            = 0;
  450.                             ScrollLines[Start + i].Right        = LastColumn + 1;
  451.                             ScrollLines[Start + i].ColourMask    = BackPen;
  452.                             ScrollLines[Start + i].Width        = TextFontWidth;
  453.                         }
  454.                     }
  455.                     else
  456.                     {
  457.                         LONG Offset = Size - Lines;
  458.  
  459.                         for(i = 1 ; i <= Offset ; i++)
  460.                             ScrollLines[Start + Size - i] = ScrollLines[Start + Size - (i + Lines)];
  461.  
  462.                         for(i = 0 ; i < Lines ; i++)
  463.                         {
  464.                             ScrollLines[Start + i].Left            = 0;
  465.                             ScrollLines[Start + i].Right        = LastColumn + 1;
  466.                             ScrollLines[Start + i].ColourMask    = BackPen;
  467.                             ScrollLines[Start + i].Width        = TextFontWidth;
  468.                         }
  469.                     }
  470.                 }
  471.                 else
  472.                 {
  473.                     if(Size <= Lines)
  474.                     {
  475.                         for(i = 0 ; i < Size ; i++)
  476.                         {
  477.                             ScrollLines[Start + i].Left            = 0;
  478.                             ScrollLines[Start + i].Right        = LastColumn + 1;
  479.                             ScrollLines[Start + i].ColourMask    = BackPen;
  480.                             ScrollLines[Start + i].Width        = TextFontWidth;
  481.                         }
  482.                     }
  483.                     else
  484.                     {
  485.                         LONG Offset = Size - Lines;
  486.  
  487.                         for(i = 0 ; i < Offset ; i++)
  488.                             ScrollLines[Start + i] = ScrollLines[Start + Lines + i];
  489.  
  490.                         for(i = Offset ; i < Size ; i++)
  491.                         {
  492.                             ScrollLines[Start + i].Left            = 0;
  493.                             ScrollLines[Start + i].Right        = LastColumn + 1;
  494.                             ScrollLines[Start + i].ColourMask    = BackPen;
  495.                             ScrollLines[Start + i].Width        = TextFontWidth;
  496.                         }
  497.                     }
  498.                 }
  499.             }
  500.         }
  501.         else
  502.         {
  503.             LONG ScrollLineLeft,ScrollLineRight,ScrollLineWidth;
  504.  
  505.             ScrollLineLeft    = 32767;
  506.             ScrollLineRight    = 0;
  507.             ScrollLineWidth    = 0;
  508.  
  509.             if(UseMasking)
  510.             {
  511.                 LONG Mask,i;
  512.  
  513.                 Mask = 0;
  514.  
  515.                 for(i = Start ; i <= Stop ; i++)
  516.                 {
  517.                     if(ScrollLines[i].Width)
  518.                     {
  519.                         if(ScrollLines[i].Left < ScrollLineLeft)
  520.                             ScrollLineLeft = ScrollLines[i].Left;
  521.  
  522.                         if(ScrollLines[i].Right > ScrollLineRight)
  523.                             ScrollLineRight = ScrollLines[i].Right;
  524.  
  525.                         if(ScrollLines[i].Width > ScrollLineWidth)
  526.                             ScrollLineWidth = ScrollLines[i].Width;
  527.  
  528.                         Mask |= ScrollLines[i].ColourMask;
  529.                     }
  530.                 }
  531.  
  532.                 if(Mask)
  533.                     SetMask(RPort,Mask);
  534.                 else
  535.                 {
  536.                     if(ResetPen)
  537.                         SetBPen(RPort,BgPen);
  538.  
  539.                     return;
  540.                 }
  541.             }
  542.             else
  543.             {
  544.                 if(!DeltaX)
  545.                 {
  546.                     LONG i;
  547.  
  548.                     for(i = Start ; i <= Stop ; i++)
  549.                     {
  550.                         if(ScrollLines[i].Width)
  551.                         {
  552.                             if(ScrollLines[i].Left < ScrollLineLeft)
  553.                                 ScrollLineLeft = ScrollLines[i].Left;
  554.  
  555.                             if(ScrollLines[i].Right > ScrollLineRight)
  556.                                 ScrollLineRight = ScrollLines[i].Right;
  557.  
  558.                             if(ScrollLines[i].Width > ScrollLineWidth)
  559.                                 ScrollLineWidth = ScrollLines[i].Width;
  560.                         }
  561.                     }
  562.                 }
  563.             }
  564.  
  565.             if(DeltaX)
  566.             {
  567.                 if(!ScrollLines[CursorY].Width)
  568.                 {
  569.                     if(ResetPen)
  570.                         SetBPen(RPort,BgPen);
  571.  
  572.                     return;
  573.                 }
  574.                 else
  575.                 {
  576.                     LONG Last;
  577.  
  578.                     Last = (LastPixel + 1) / ScrollLines[CursorY].Width;
  579.  
  580.                     if(DeltaX > 0)
  581.                         ScrollLines[CursorY].Left -= DeltaX / ScrollLines[CursorY].Width;
  582.                     else
  583.                         ScrollLines[CursorY].Right -= DeltaX / ScrollLines[CursorY].Width;
  584.  
  585.                     if(ScrollLines[CursorY].Right < 0)
  586.                         ScrollLines[CursorY].Right = 0;
  587.                     else
  588.                     {
  589.                         if(ScrollLines[CursorY].Right > Last)
  590.                             ScrollLines[CursorY].Right = Last;
  591.                     }
  592.  
  593.                     if(ScrollLines[CursorY].Left < 0)
  594.                         ScrollLines[CursorY].Left = 0;
  595.                     else
  596.                     {
  597.                         if(ScrollLines[CursorY].Left > Last)
  598.                             ScrollLines[CursorY].Left = Last;
  599.                     }
  600.                 }
  601.             }
  602.             else
  603.             {
  604.                 LONG Lines,Size,i;
  605.  
  606.                 Lines    = DeltaY / TextFontHeight;
  607.                 Size    = (MaxY - MinY + 1) / TextFontHeight;
  608.  
  609.                 if(Lines < 0)
  610.                 {
  611.                     Lines = -Lines;
  612.  
  613.                     if(Size <= Lines)
  614.                     {
  615.                         for(i = 0 ; i < Size ; i++)
  616.                         {
  617.                             ScrollLines[Start + i].Left            = 32767;
  618.                             ScrollLines[Start + i].Right        = 0;
  619.                             ScrollLines[Start + i].ColourMask    = 0;
  620.                             ScrollLines[Start + i].Width        = 0;
  621.                         }
  622.                     }
  623.                     else
  624.                     {
  625.                         LONG Offset;
  626.  
  627.                         Offset = Size - Lines;
  628.  
  629.                         for(i = 1 ; i <= Offset ; i++)
  630.                             ScrollLines[Start + Size - i] = ScrollLines[Start + Size - (i + Lines)];
  631.  
  632.                         for(i = 0 ; i < Lines ; i++)
  633.                         {
  634.                             ScrollLines[Start + i].Left            = 32767;
  635.                             ScrollLines[Start + i].Right        = 0;
  636.                             ScrollLines[Start + i].ColourMask    = 0;
  637.                             ScrollLines[Start + i].Width        = 0;
  638.                         }
  639.                     }
  640.                 }
  641.                 else
  642.                 {
  643.                     if(Size <= Lines)
  644.                     {
  645.                         for(i = 0 ; i < Size ; i++)
  646.                         {
  647.                             ScrollLines[Start + i].Left            = 32767;
  648.                             ScrollLines[Start + i].Right        = 0;
  649.                             ScrollLines[Start + i].ColourMask    = 0;
  650.                             ScrollLines[Start + i].Width        = 0;
  651.                         }
  652.                     }
  653.                     else
  654.                     {
  655.                         LONG Offset;
  656.  
  657.                         Offset = Size - Lines;
  658.  
  659.                         for(i = 0 ; i < Offset ; i++)
  660.                             ScrollLines[Start + i] = ScrollLines[Start + Lines + i];
  661.  
  662.                         for(i = Offset ; i < Size ; i++)
  663.                         {
  664.                             ScrollLines[Start + i].Left            = 32767;
  665.                             ScrollLines[Start + i].Right        = 0;
  666.                             ScrollLines[Start + i].ColourMask    = 0;
  667.                             ScrollLines[Start + i].Width        = 0;
  668.                         }
  669.                     }
  670.                 }
  671.  
  672.                 if(ScrollLineWidth)
  673.                 {
  674.                     LONG Temp;
  675.  
  676.                     if((Temp = ScrollLineLeft * ScrollLineWidth) > MinX)
  677.                         MinX = Temp;
  678.  
  679.                     if((Temp = ScrollLineRight * ScrollLineWidth) < MaxX)
  680.                         MaxX = Temp;
  681.  
  682.                     if(MaxX == ScrollLineRight)
  683.                         MaxX += FontRightExtend;    /* Add margin for italics or boldface. */
  684.  
  685.                     if(DeltaY < 0)
  686.                     {
  687.                         if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  688.                             MinY = Temp;
  689.  
  690.                         if((Temp = MUL_Y(ScrollLineLast + 1) - 1 - DeltaY) < MaxY)
  691.                             MaxY = Temp;
  692.                     }
  693.                     else
  694.                     {
  695.                         if(DeltaY > 0)
  696.                         {
  697.                             if((Temp = MUL_Y(ScrollLineFirst) - DeltaY) > MinY)
  698.                                 MinY = Temp;
  699.  
  700.                             if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  701.                                 MaxY = Temp;
  702.                         }
  703.                     }
  704.  
  705.                     if(MinX < 0)
  706.                         MinX = 0;
  707.  
  708.                     if(MaxX < 0)
  709.                         MaxX = 0;
  710.  
  711.                     if(MinY < 0)
  712.                         MinY = 0;
  713.  
  714.                     if(MaxY < 0)
  715.                         MaxY = 0;
  716.                 }
  717.                 else
  718.                 {
  719.                     ScrollFrameUpdate();
  720.  
  721.                     if(ResetPen)
  722.                         SetBPen(RPort,BgPen);
  723.  
  724.                     return;
  725.                 }
  726.             }
  727.         }
  728.  
  729.         if(Start < ScrollLineFirst)
  730.             ScrollLineFirst = Start;
  731.  
  732.         if(Stop > ScrollLineLast)
  733.             ScrollLineLast = Stop;
  734.  
  735.         ScrollFrameUpdate();
  736.  
  737.         if(MinX < MaxX && MinY < MaxY)
  738.         {
  739.             MinX += WindowLeft;
  740.             MaxX += WindowLeft;
  741.  
  742.             MinY += WindowTop;
  743.             MaxY += WindowTop;
  744.  
  745.                 /* Smooth scrolling requested? */
  746.  
  747.             if(Smooth && DeltaY)
  748.             {
  749.                 LONG Lines,Extra,Direction;
  750.  
  751.                 Lines = ABS(DeltaY);
  752.                 Extra = Lines & 1;
  753.                 Lines = Lines / 2;
  754.  
  755.                 if(DeltaY > 0)
  756.                     Direction = 2;
  757.                 else
  758.                     Direction = -2;
  759.  
  760.                 while(Lines-- > 0)
  761.                 {
  762.                     WaitBlit();
  763.                     WaitTOF();
  764.                     ScrollRaster(RPort,0,Direction,MinX,MinY,MaxX,MaxY);
  765.                 }
  766.  
  767.                 if(Extra)
  768.                 {
  769.                     WaitBlit();
  770.                     WaitTOF();
  771.                     ScrollRaster(RPort,0,Direction / 2,MinX,MinY,MaxX,MaxY);
  772.                 }
  773.             }
  774.             else
  775.                 ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
  776.         }
  777.  
  778.         if(ResetPen)
  779.             SetBPen(RPort,BgPen);
  780.     }
  781. }
  782.  
  783. VOID
  784. ScrollLineRasterNoTabChange(struct RastPort *RPort,LONG DeltaX,LONG DeltaY,LONG MinX,LONG MinY,LONG MaxX,LONG MaxY,BOOL Smooth)
  785. {
  786.     if((DeltaX || DeltaY) && MinX < MaxX && MinY < MaxY)
  787.     {
  788.         LONG Start,Stop;
  789.         LONG BackPen;
  790.         BOOL ResetPen;
  791.  
  792.         if((Attributes & ATTR_INVERSE) && (FgPen != BgPen))
  793.         {
  794.             SetBPen(RPort,FgPen);
  795.  
  796.             ResetPen    = TRUE;
  797.             BackPen        = FgPen;
  798.         }
  799.         else
  800.         {
  801.             ResetPen    = FALSE;
  802.             BackPen        = BgPen;
  803.         }
  804.  
  805.         Start    = MinY / TextFontHeight;
  806.         Stop    = MaxY / TextFontHeight;
  807.  
  808.         if(BackPen)
  809.         {
  810.             if(UseMasking)
  811.             {
  812.                 LONG i,Mask = BackPen;
  813.  
  814.                 for(i = Start ; i <= Stop ; i++)
  815.                 {
  816.                     if(ScrollLines[i].Width)
  817.                         Mask |= ScrollLines[i].ColourMask;
  818.                 }
  819.  
  820.                 SetMask(RPort,Mask);
  821.             }
  822.  
  823.             if(DeltaX)
  824.             {
  825.                 if(!ScrollLines[CursorY].Width)
  826.                 {
  827.                     if(ResetPen)
  828.                         SetBPen(RPort,BgPen);
  829.  
  830.                     return;
  831.                 }
  832.             }
  833.         }
  834.         else
  835.         {
  836.             LONG ScrollLineLeft,ScrollLineRight,ScrollLineWidth;
  837.  
  838.             ScrollLineLeft    = 32767;
  839.             ScrollLineRight    = 0;
  840.             ScrollLineWidth    = 0;
  841.  
  842.             if(UseMasking)
  843.             {
  844.                 LONG i,Mask;
  845.  
  846.                 Mask = 0;
  847.  
  848.                 for(i = Start ; i <= Stop ; i++)
  849.                 {
  850.                     if(ScrollLines[i].Width)
  851.                     {
  852.                         if(ScrollLines[i].Left < ScrollLineLeft)
  853.                             ScrollLineLeft = ScrollLines[i].Left;
  854.  
  855.                         if(ScrollLines[i].Right > ScrollLineRight)
  856.                             ScrollLineRight = ScrollLines[i].Right;
  857.  
  858.                         if(ScrollLines[i].Width > ScrollLineWidth)
  859.                             ScrollLineWidth = ScrollLines[i].Width;
  860.  
  861.                         Mask |= ScrollLines[i].ColourMask;
  862.                     }
  863.                 }
  864.  
  865.                 if(Mask)
  866.                     SetMask(RPort,Mask);
  867.                 else
  868.                 {
  869.                     if(ResetPen)
  870.                         SetBPen(RPort,BgPen);
  871.  
  872.                     return;
  873.                 }
  874.             }
  875.             else
  876.             {
  877.                 if(!DeltaX)
  878.                 {
  879.                     LONG i;
  880.  
  881.                     for(i = Start ; i <= Stop ; i++)
  882.                     {
  883.                         if(ScrollLines[i].Width)
  884.                         {
  885.                             if(ScrollLines[i].Left < ScrollLineLeft)
  886.                                 ScrollLineLeft = ScrollLines[i].Left;
  887.  
  888.                             if(ScrollLines[i].Right > ScrollLineRight)
  889.                                 ScrollLineRight = ScrollLines[i].Right;
  890.  
  891.                             if(ScrollLines[i].Width > ScrollLineWidth)
  892.                                 ScrollLineWidth = ScrollLines[i].Width;
  893.                         }
  894.                     }
  895.                 }
  896.             }
  897.  
  898.             if(DeltaX)
  899.             {
  900.                 if(!ScrollLines[CursorY].Width)
  901.                 {
  902.                     if(ResetPen)
  903.                         SetBPen(RPort,BgPen);
  904.  
  905.                     return;
  906.                 }
  907.             }
  908.             else
  909.             {
  910.                 if(ScrollLineWidth)
  911.                 {
  912.                     LONG Temp;
  913.  
  914.                     if((Temp = ScrollLineLeft * ScrollLineWidth) > MinX)
  915.                         MinX = Temp;
  916.  
  917.                     if((Temp = ScrollLineRight * ScrollLineWidth) < MaxX)
  918.                         MaxX = Temp;
  919.  
  920.                     if(MaxX == ScrollLineRight)
  921.                         MaxX += FontRightExtend;    /* Add margin for italics or boldface. */
  922.  
  923.                     if(DeltaY < 0)
  924.                     {
  925.                         if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  926.                             MinY = Temp;
  927.  
  928.                         if((Temp = MUL_Y(ScrollLineLast + 1) - 1 - DeltaY) < MaxY)
  929.                             MaxY = Temp;
  930.                     }
  931.                     else
  932.                     {
  933.                         if(DeltaY > 0)
  934.                         {
  935.                             if((Temp = MUL_Y(ScrollLineFirst) - DeltaY) > MinY)
  936.                                 MinY = Temp;
  937.  
  938.                             if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  939.                                 MaxY = Temp;
  940.                         }
  941.                     }
  942.  
  943.                     if(MinX < 0)
  944.                         MinX = 0;
  945.  
  946.                     if(MaxX < 0)
  947.                         MaxX = 0;
  948.  
  949.                     if(MinY < 0)
  950.                         MinY = 0;
  951.  
  952.                     if(MaxY < 0)
  953.                         MaxY = 0;
  954.                 }
  955.                 else
  956.                 {
  957.                     ScrollFrameUpdate();
  958.  
  959.                     if(ResetPen)
  960.                         SetBPen(RPort,BgPen);
  961.  
  962.                     return;
  963.                 }
  964.             }
  965.         }
  966.  
  967.         if(Start < ScrollLineFirst)
  968.             ScrollLineFirst = Start;
  969.  
  970.         if(Stop > ScrollLineLast)
  971.             ScrollLineLast = Stop;
  972.  
  973.         ScrollFrameUpdate();
  974.  
  975.         if(MinX < MaxX && MinY < MaxY)
  976.         {
  977.             MinX += WindowLeft;
  978.             MaxX += WindowLeft;
  979.  
  980.             MinY += WindowTop;
  981.             MaxY += WindowTop;
  982.  
  983.                 /* Smooth scrolling requested? */
  984.  
  985.             if(Smooth && DeltaY)
  986.             {
  987.                 LONG Lines,Extra,Direction;
  988.  
  989.                 Lines = ABS(DeltaY);
  990.                 Extra = Lines & 1;
  991.                 Lines = Lines / 2;
  992.  
  993.                 if(DeltaY > 0)
  994.                     Direction = 2;
  995.                 else
  996.                     Direction = -2;
  997.  
  998.                 while(Lines-- > 0)
  999.                 {
  1000.                     WaitBlit();
  1001.                     WaitTOF();
  1002.                     ScrollRaster(RPort,0,Direction,MinX,MinY,MaxX,MaxY);
  1003.                 }
  1004.  
  1005.                 if(Extra)
  1006.                 {
  1007.                     WaitBlit();
  1008.                     WaitTOF();
  1009.                     ScrollRaster(RPort,0,Direction / 2,MinX,MinY,MaxX,MaxY);
  1010.                 }
  1011.             }
  1012.             else
  1013.                 ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
  1014.         }
  1015.  
  1016.         if(ResetPen)
  1017.             SetBPen(RPort,BgPen);
  1018.     }
  1019. }
  1020.  
  1021.     /* ScrollLineEraseScreen(BYTE Mode):
  1022.      *
  1023.      *    Erase a part of the screen.
  1024.      */
  1025.  
  1026. VOID
  1027. ScrollLineEraseScreen(LONG Mode)
  1028. {
  1029.     LONG i;
  1030.  
  1031.     if(BgPen)
  1032.     {
  1033.         switch(Mode)
  1034.         {
  1035.                 /* Erase from first line to current cursor position (inclusive). */
  1036.  
  1037.             case 1:
  1038.  
  1039.                 ScrollLineFirst = CursorY;
  1040.  
  1041.                 if(ScrollLineLast < CursorY)
  1042.                     ScrollLineLast = CursorY;
  1043.  
  1044.                     /* Reset the lines. */
  1045.  
  1046.                 for(i = 0 ; i < CursorY ; i++)
  1047.                 {
  1048.                     ScrollLines[i].Left            = 0;
  1049.                     ScrollLines[i].Right        = LastColumn + 1;
  1050.                     ScrollLines[i].ColourMask    = BgPen;
  1051.                     ScrollLines[i].Width        = TextFontWidth;
  1052.                 }
  1053.  
  1054.                 if(CursorX)
  1055.                 {
  1056.                     if(!ScrollLines[CursorY].Width)
  1057.                         ScrollLines[CursorY].Width = GetFontWidth();
  1058.  
  1059.                     ScrollLines[CursorY].Left        = 0;
  1060.                     ScrollLines[CursorY].ColourMask    |= BgPen;
  1061.                 }
  1062.  
  1063.                 break;
  1064.  
  1065.                 /* Erase entire screen. */
  1066.  
  1067.             case 2:
  1068.  
  1069.                 for(i = 0 ; i < RasterHeight ; i++)
  1070.                 {
  1071.                     ScrollLines[i].Left            = 0;
  1072.                     ScrollLines[i].Right        = LastColumn + 1;
  1073.                     ScrollLines[i].ColourMask    = BgPen;
  1074.                     ScrollLines[i].Width        = TextFontWidth;
  1075.                 }
  1076.  
  1077.                 ScrollLineFirst    = 0;
  1078.                 ScrollLineLast    = RasterHeight - 1;
  1079.  
  1080.                 break;
  1081.  
  1082.                 /* Erase from current cursor position to end of screen. */
  1083.  
  1084.             default:
  1085.  
  1086.                 for(i = CursorY + 1 ; i < RasterHeight ; i++)
  1087.                 {
  1088.                     ScrollLines[i].Left            = 0;
  1089.                     ScrollLines[i].Right        = LastColumn + 1;
  1090.                     ScrollLines[i].ColourMask    = BgPen;
  1091.                     ScrollLines[i].Width        = TextFontWidth;
  1092.                 }
  1093.  
  1094.                 if(!ScrollLines[CursorY].Width)
  1095.                     ScrollLines[CursorY].Width = GetFontWidth();
  1096.  
  1097.                 ScrollLines[CursorY].Right = (LastPixel + 1) / ScrollLines[CursorY].Width;
  1098.  
  1099.                 if(CursorX)
  1100.                     ScrollLines[CursorY].ColourMask |= BgPen;
  1101.                 else
  1102.                     ScrollLines[CursorY].ColourMask = BgPen;
  1103.  
  1104.                 if(ScrollLineFirst > CursorY)
  1105.                     ScrollLineFirst = CursorY;
  1106.  
  1107.                 ScrollLineLast = RasterHeight - 1;
  1108.  
  1109.                 break;
  1110.         }
  1111.     }
  1112.     else
  1113.     {
  1114.         switch(Mode)
  1115.         {
  1116.                 /* Erase from first line to current cursor line (inclusive). */
  1117.  
  1118.             case 1:
  1119.  
  1120.                     /* Reset the lines. */
  1121.  
  1122.                 for(i = 0 ; i < CursorY ; i++)
  1123.                 {
  1124.                     ScrollLines[i].Left            = 32767;
  1125.                     ScrollLines[i].Right        = 0;
  1126.                     ScrollLines[i].ColourMask    = 0;
  1127.                     ScrollLines[i].Width        = 0;
  1128.                 }
  1129.  
  1130.                 ScrollLines[CursorY].Left = CursorX;
  1131.  
  1132.                 if(ScrollLines[CursorY].Right < ScrollLines[CursorY].Left)
  1133.                 {
  1134.                     ScrollLines[CursorY].Left    = 32767;
  1135.                     ScrollLines[CursorY].Right    = 0;
  1136.                     ScrollLines[CursorY].Width    = 0;
  1137.  
  1138.                         /* Cleared the entire screen? */
  1139.  
  1140.                     if(CursorY == RasterHeight - 1)
  1141.                     {
  1142.                         ScrollLineFirst    = 32767;
  1143.                         ScrollLineLast    = 0;
  1144.                     }
  1145.                     else
  1146.                         ScrollLineFirst = CursorY;
  1147.                 }
  1148.                 else
  1149.                     ScrollLineFirst = CursorY;
  1150.  
  1151.                 if(ScrollLineLast < CursorY)
  1152.                     ScrollLineLast = CursorY;
  1153.  
  1154.                 break;
  1155.  
  1156.                 /* Erase entire screen. */
  1157.  
  1158.             case 2:
  1159.  
  1160.                 for(i = 0 ; i < RasterHeight ; i++)
  1161.                 {
  1162.                     ScrollLines[i].Left            = 32767;
  1163.                     ScrollLines[i].Right        = 0;
  1164.                     ScrollLines[i].ColourMask    = 0;
  1165.                     ScrollLines[i].Width        = 0;
  1166.                 }
  1167.  
  1168.                 ScrollLineFirst    = 32767;
  1169.                 ScrollLineLast    = 0;
  1170.  
  1171.                 break;
  1172.  
  1173.                 /* Erase from current cursor position to end of screen. */
  1174.  
  1175.             default:
  1176.  
  1177.                 for(i = CursorY + 1 ; i < RasterHeight ; i++)
  1178.                 {
  1179.                     ScrollLines[i].Left            = 32767;
  1180.                     ScrollLines[i].Right        = 0;
  1181.                     ScrollLines[i].ColourMask    = 0;
  1182.                     ScrollLines[i].Width        = 0;
  1183.                 }
  1184.  
  1185.                 if(CursorX)
  1186.                 {
  1187.                     ScrollLines[CursorY].Right = CursorX;
  1188.  
  1189.                     if(ScrollLines[CursorY].Right < ScrollLines[CursorY].Left)
  1190.                     {
  1191.                         ScrollLines[CursorY].Left    = 32767;
  1192.                         ScrollLines[CursorY].Right    = 0;
  1193.                         ScrollLines[CursorY].Width    = 0;
  1194.                     }
  1195.                 }
  1196.                 else
  1197.                 {
  1198.                     ScrollLines[CursorY].Left    = 32767;
  1199.                     ScrollLines[CursorY].Right    = 0;
  1200.                     ScrollLines[CursorY].Width    = 0;
  1201.                 }
  1202.  
  1203.                 /* Cleared the entire screen? */
  1204.  
  1205.                 if(CursorY)
  1206.                     ScrollLineLast = CursorY;
  1207.                 else
  1208.                 {
  1209.                     if(ScrollLines[CursorY].Right < ScrollLines[CursorY].Left)
  1210.                     {
  1211.                         ScrollLineFirst    = 32767;
  1212.                         ScrollLineLast    = 0;
  1213.                     }
  1214.                     else
  1215.                     {
  1216.                         if(ScrollLineFirst > CursorY)
  1217.                             ScrollLineFirst = CursorY;
  1218.                     }
  1219.                 }
  1220.  
  1221.                 break;
  1222.         }
  1223.     }
  1224.  
  1225.     ScrollFrameUpdate();
  1226. }
  1227.  
  1228.     /* ScrollLineEraseLine(BYTE Mode):
  1229.      *
  1230.      *    Erase parts of the current cursor line.
  1231.      */
  1232.  
  1233. VOID
  1234. ScrollLineEraseLine(LONG Mode)
  1235. {
  1236.     if(BgPen)
  1237.     {
  1238.         switch(Mode)
  1239.         {
  1240.                 /* Erase from left margin to current cursor position (inclusive). */
  1241.  
  1242.             case 1:
  1243.  
  1244.                 ScrollLines[CursorY].Left = 0;
  1245.  
  1246.                 ScrollLines[CursorY].ColourMask |= BgPen;
  1247.  
  1248.                 if(!ScrollLines[CursorY].Width)
  1249.                     ScrollLines[CursorY].Width = GetFontWidth();
  1250.  
  1251.                 break;
  1252.  
  1253.                 /* Erase entire line. */
  1254.  
  1255.             case 2:
  1256.  
  1257.                 ScrollLines[CursorY].Width        = GetFontWidth();
  1258.                 ScrollLines[CursorY].Left        = 0;
  1259.                 ScrollLines[CursorY].Right        = (LastPixel + 1) / ScrollLines[CursorY].Width;
  1260.                 ScrollLines[CursorY].ColourMask    = BgPen;
  1261.  
  1262.                 break;
  1263.  
  1264.                 /* Erase from current cursor position towards end of line. */
  1265.  
  1266.             default:
  1267.  
  1268.                 if(CursorX)
  1269.                 {
  1270.                     if(!ScrollLines[CursorY].Width)
  1271.                         ScrollLines[CursorY].Width = GetFontWidth();
  1272.  
  1273.                     ScrollLines[CursorY].ColourMask |= BgPen;
  1274.                 }
  1275.                 else
  1276.                 {
  1277.                     ScrollLines[CursorY].Width        = GetFontWidth();
  1278.                     ScrollLines[CursorY].Left        = 0;
  1279.                     ScrollLines[CursorY].ColourMask    = BgPen;
  1280.                 }
  1281.  
  1282.                 ScrollLines[CursorY].Right = (LastPixel + 1) / ScrollLines[CursorY].Width;
  1283.                 break;
  1284.         }
  1285.     }
  1286.     else
  1287.     {
  1288.         switch(Mode)
  1289.         {
  1290.                 /* Erase from left margin to current cursor position (inclusive). */
  1291.  
  1292.             case 1:
  1293.  
  1294.                 ScrollLines[CursorY].Left = CursorX;
  1295.  
  1296.                 if(ScrollLines[CursorY].Left >= ScrollLines[CursorY].Right)
  1297.                 {
  1298.                     ScrollLines[CursorY].Left    = 32767;
  1299.                     ScrollLines[CursorY].Right    = 0;
  1300.                     ScrollLines[CursorY].Width    = 0;
  1301.                 }
  1302.  
  1303.                 break;
  1304.  
  1305.                 /* Erase entire line. */
  1306.  
  1307.             case 2:
  1308.  
  1309.                 ScrollLines[CursorY].Left    = 32767;
  1310.                 ScrollLines[CursorY].Right    = 0;
  1311.                 ScrollLines[CursorY].Width    = 0;
  1312.  
  1313.                 break;
  1314.  
  1315.                 /* Erase from current cursor position towards end of line. */
  1316.  
  1317.             default:
  1318.  
  1319.                 if(CursorX)
  1320.                     ScrollLines[CursorY].Right = CursorX;
  1321.                 else
  1322.                 {
  1323.                     ScrollLines[CursorY].Left    = 32767;
  1324.                     ScrollLines[CursorY].Right    = 0;
  1325.                     ScrollLines[CursorY].Width    = 0;
  1326.                 }
  1327.  
  1328.                 break;
  1329.         }
  1330.     }
  1331.  
  1332.     ScrollFrameUpdate();
  1333. }
  1334.  
  1335.     /* ScrollLineEraseCharacters(LONG Chars):
  1336.      *
  1337.      *    Erase a number of characters in the current cursor line.
  1338.      */
  1339.  
  1340. VOID
  1341. ScrollLineEraseCharacters(LONG Chars)
  1342. {
  1343.         /* Any characters to erase? */
  1344.  
  1345.     if(BgPen)
  1346.     {
  1347.         if(!ScrollLines[CursorY].Width)
  1348.             ScrollLines[CursorY].Width = GetFontWidth();
  1349.  
  1350.         ScrollLines[CursorY].Left    = 0;
  1351.         ScrollLines[CursorY].Right    = (LastPixel + 1) / ScrollLines[CursorY].Width;
  1352.  
  1353.         ScrollLines[CursorY].ColourMask |= BgPen;
  1354.     }
  1355.     else
  1356.     {
  1357.         if(ScrollLines[CursorY].Right > Chars)
  1358.             ScrollLines[CursorY].Right -= Chars;
  1359.         else
  1360.             ScrollLines[CursorY].Right = 0;
  1361.     }
  1362. }
  1363.  
  1364.     /* ScrollLineShiftChar(LONG Size):
  1365.      *
  1366.      *    Shift the characters following the current cursor position
  1367.      *    Size characters to the right.
  1368.      */
  1369.  
  1370. VOID
  1371. ScrollLineShiftChar(LONG Size)
  1372. {
  1373.         /* Any characters to scroll? */
  1374.  
  1375.     if(BgPen)
  1376.     {
  1377.         if(!ScrollLines[CursorY].Width)
  1378.             ScrollLines[CursorY].Width = GetFontWidth();
  1379.  
  1380.         ScrollLines[CursorY].Left    = 0;
  1381.         ScrollLines[CursorY].Right    = (LastPixel + 1) / ScrollLines[CursorY].Width;
  1382.  
  1383.         ScrollLines[CursorY].ColourMask |= BgPen;
  1384.     }
  1385.     else
  1386.     {
  1387.         LONG Temp;
  1388.  
  1389.         ScrollLines[CursorY].Right += Size;
  1390.  
  1391.         if((Temp = ScrollLines[CursorY].Right * ScrollLines[CursorY].Width) > LastPixel)
  1392.             ScrollLines[CursorY].Right = (LastPixel + 1) / ScrollLines[CursorY].Width;
  1393.         else
  1394.         {
  1395.             if(ScrollLines[CursorY].Right < 0)
  1396.                 ScrollLines[CursorY].Right = 0;
  1397.         }
  1398.     }
  1399. }
  1400.  
  1401.     /* ScrollLinePutString(LONG Length):
  1402.      *
  1403.      *    Update the line info according to the length of a string
  1404.      *    to be printed.
  1405.      */
  1406.  
  1407. VOID
  1408. ScrollLinePutString(LONG Length)
  1409. {
  1410.     if(Length)
  1411.     {
  1412.         LONG Width;
  1413.  
  1414.             /* Which scale is the font we are currently using? */
  1415.  
  1416.         if(RasterAttr[CursorY] >= SCALE_ATTR_TOP2X)
  1417.         {
  1418.                 /* Valid length? */
  1419.  
  1420.             if(CursorX + Length >= RasterWidth / 2)
  1421.                 Length = (RasterWidth / 2) - CursorX;
  1422.  
  1423.                 /* Double width. */
  1424.  
  1425.             Width = TextFontWidth * 2;
  1426.         }
  1427.         else
  1428.         {
  1429.             if(CurrentCharWidth == SCALE_HALF)
  1430.             {
  1431.                     /* Valid length? */
  1432.  
  1433.                 if(CursorX + Length >= RasterWidth * 2)
  1434.                     Length = (RasterWidth * 2) - CursorX;
  1435.  
  1436.                     /* Half width. */
  1437.  
  1438.                 Width = TextFontWidth / 2;
  1439.             }
  1440.             else
  1441.             {
  1442.                     /* Valid length? */
  1443.  
  1444.                 if(CursorX + Length >= RasterWidth)
  1445.                     Length = RasterWidth - CursorX;
  1446.  
  1447.                     /* Normal width. */
  1448.  
  1449.                 Width = TextFontWidth;
  1450.             }
  1451.         }
  1452.  
  1453.             /* Sensible value? */
  1454.  
  1455.         if(Length > 0)
  1456.         {
  1457.             struct ScrollLineInfo *Alias;
  1458.  
  1459.             Alias = &ScrollLines[CursorY];
  1460.  
  1461.                 /* Update font scale. */
  1462.  
  1463.             Alias->Width = Width;
  1464.  
  1465.                 /* Update right margin. */
  1466.  
  1467.             if(CursorX < Alias->Left)
  1468.                 Alias->Left = CursorX;
  1469.  
  1470.                 /* Update left margin. */
  1471.  
  1472.             if(CursorX + Length > Alias->Right)
  1473.                 Alias->Right = CursorX + Length;
  1474.  
  1475.                 /* Update topmost line. */
  1476.  
  1477.             if(CursorY < ScrollLineFirst)
  1478.                 ScrollLineFirst = CursorY;
  1479.  
  1480.                 /* Update bottommost line. */
  1481.  
  1482.             if(CursorY > ScrollLineLast)
  1483.                 ScrollLineLast = CursorY;
  1484.  
  1485.             if(UseMasking)
  1486.             {
  1487.                     /* Update line colour mask. */
  1488.  
  1489.                 Alias->ColourMask |= FgPen | BgPen;
  1490.  
  1491.                     /* Set write mask (will affect Text() since it is called
  1492.                      * after this routine has finished.
  1493.                      */
  1494.  
  1495.                 SetMask(RPort,Alias->ColourMask);
  1496.             }
  1497.         }
  1498.     }
  1499. }
  1500.